package com.wang.springframework.aop.framework;

import com.wang.springframework.aop.AdvisedSupport;

/**
 * @author wangjianhua
 * @Description 解决jdk或者cglib两种代理的选择 可以根据不同的需求创建代理
 * @date 2021/9/3/003 14:22
 **/
public class ProxyFactory {

    private AdvisedSupport advisedSupport;

    public ProxyFactory(AdvisedSupport advisedSupport) {
        this.advisedSupport = advisedSupport;
    }

    public Object getProxy(){
        return creatAopProxy().getProxy();
    }

    public AopProxy creatAopProxy(){
        if(advisedSupport.isProxyTargetClass()){
            return new Cglib2AopProxy(advisedSupport);
        }

        return new JdkDynamicAopProxy(advisedSupport);
    }
}
